import { Injectable, UseGuards } from '@nestjs/common';
import { CreateInformationDto } from './dto/information.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Types } from './entities/types.entity';
import { Repository } from 'typeorm';
import { TokenAuth } from 'src/common/gaurd/tokenAuth.gaurd';
import { Information } from './entities/information.entity';
@Injectable()
export class InformationService {
  constructor(
    @InjectRepository(Types) private typeModel: Repository<Types>,
    @InjectRepository(Information) private informationModel: Repository<Information>,
  ) {}
  /**
   * @author nie
   * @description 查询分类列表
   * @email a896211755@gmail.com
   */
  async getTypeList(): Promise<Types[]> {
    return await this.typeModel.find({
      select: ['name', 'id'],
    });
  }
  /**
   * @author nie
   * @description 添加分类
   * @email a896211755@gmail.com
   */
  async addType(name: string) {
    let val = new Types();
    val.name = name;
    return await this.typeModel.save(val);
  }
  /**
  * @author nie
  * @description 发布文章
  * @email a896211755@gmail.com
  */
  async publicInformation(user_id: number, content: string, title: string, days: number, type_id: number) {
    let information = new Information();
    information.user_id = user_id;
    information.content = content;
    information.title = title;
    information.days = days;
    information.type_id = type_id;
    return await this.informationModel.save(information)
  }
}
